<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * Login Application (Auth), Index/Form Module (Backend)
 * Started: 19 September, 2009 09:14 PM
 * Script version: 1.0
 +------------------------------------
 */

class module implements module_interface{
	public function returninitvars(){
		global $lang;
		$this->info["page_title"] = $lang->getByKey("admin.secure.securetools");
		$this->info["page_description"] = "";
		$this->info["module_version"] = "1.0";
		return $this->info;
	}

	public function construct(){ # call our initialize functions
	}
	
	public function makeToolTPL($title, $desc, $ok = false, $runToolLink = ""){
		global $view;
		if($ok == false){
			$desc = $view->showTemplate("sectool", array("desc" => $desc, "link" => $runToolLink));
		}
		return $view->tablePadded($title, $desc, ($ok ? "accept" : "stop"));
	}
	
	public function runTools($tool){
		global $view, $lang;
		switch($tool){
			case "conf":
				if(@chmod(CONF_FILE, 0644) and !IN_WINDOWS){
					$view->writeIn($view->inlineSuccess($lang->getByKey("admin.secure.tools.conffile.ranok")));
				}
				else{
					$view->writeIn($view->inlineError($lang->getByKey("admin.secure.tools.conffile.ranfail")));
				}
			break;
			default:
				$view->writeIn($view->inlineWarning($lang->getByKey("admin.secure.tools.notfound")));
			break;
		}
	}
	
	public function run(){
		global $view, $lang, $db, $models;
		$view->writeIn( $view->inlineInfo($lang->getByKey("admin.secure.tools.desc")));
		if(isset($_GET['tool'])){
			$this->runTools($_GET['tool']);
		}
		$this->queue = "";
		// So tools... nice name.
		// Tool 1: Conf File :: Writable-d!
		if(!is_writable(CONF_FILE) or IN_WINDOWS){
			$this->queue .= $this->makeToolTpl($lang->getByKey("admin.secure.tools.conffile.ok"),
											   $lang->getByKey("admin.secure.tools.conffile.ok.desc"), true);
		}
		else{
			$this->queue .= $this->makeToolTpl($lang->getByKey("admin.secure.tools.conffile.fail"),
											   $lang->getByKey("admin.secure.tools.conffile.fail.desc"), false, "conf");
		}
		$view->writeIn($this->queue);
	}

	public function destruct(){}
}
